package com.zhumei.keyscale.weight;

import android.content.*;
import android.util.*;
import android.graphics.*;
import android.view.*;

public class CustomizedProgressBar extends View
{
    private LinearGradient linearGradient;
    private Context mContext;
    private float mCurrentCount;
    private int mHeight;
    private float mMaxCount;
    private int mWidth;
    
    public CustomizedProgressBar(final Context context) {
        super(context);
        this.mMaxCount = 100.0f;
        this.initView(context);
    }
    
    public CustomizedProgressBar(final Context context, final AttributeSet set) {
        super(context, set);
        this.mMaxCount = 100.0f;
        this.initView(context);
    }
    
    public CustomizedProgressBar(final Context context, final AttributeSet set, final int n) {
        super(context, set, n);
        this.mMaxCount = 100.0f;
        this.initView(context);
    }
    
    private int dipToPx(int n) {
        final float density = this.getContext().getResources().getDisplayMetrics().density;
        final float n2 = (float)n;
        if (n >= 0) {
            n = 1;
        }
        else {
            n = -1;
        }
        return (int)(n2 * density + n * 0.5f);
    }
    
    private LinearGradient getLinearGradient() {
        if (this.linearGradient == null) {
            this.linearGradient = new LinearGradient(0.0f, 0.0f, (float)this.getWidth(), (float)this.mHeight, new int[] { Color.parseColor("#FF916B"), Color.parseColor("#FFA94C") }, (float[])null, Shader$TileMode.CLAMP);
        }
        return this.linearGradient;
    }
    
    private void initView(final Context mContext) {
        this.mContext = mContext;
    }
    
    public float getCurrentCount() {
        return this.mCurrentCount;
    }
    
    public float getMaxCount() {
        return this.mMaxCount;
    }
    
    protected void onDraw(final Canvas canvas) {
        super.onDraw(canvas);
        final Paint paint = new Paint();
        paint.setAntiAlias(true);
        final int n = this.mHeight / 2;
        paint.setColor(Color.parseColor("#0C000000"));
        final RectF rectF = new RectF(0.0f, 0.0f, (float)this.mWidth, (float)this.mHeight);
        final float n2 = (float)n;
        canvas.drawRoundRect(rectF, n2, n2, paint);
        final float n3 = this.mCurrentCount / this.mMaxCount;
        final RectF rectF2 = new RectF(0.0f, 0.0f, this.mWidth * n3, (float)this.mHeight);
        paint.setColor(Color.parseColor("#FFFFFF"));
        paint.setShader((Shader)this.getLinearGradient());
        canvas.drawRoundRect(rectF2, n2, n2, paint);
        if (this.mMaxCount != this.mCurrentCount) {
            final int mWidth = this.mWidth;
            final RectF rectF3 = new RectF(mWidth * n3 - n2, 0.0f, mWidth * n3, (float)this.mHeight);
            paint.setShader((Shader)this.getLinearGradient());
            canvas.drawRect(rectF3, paint);
        }
    }
    
    protected void onMeasure(int size, int size2) {
        final int mode = View$MeasureSpec.getMode(size);
        size = View$MeasureSpec.getSize(size);
        final int mode2 = View$MeasureSpec.getMode(size2);
        size2 = View$MeasureSpec.getSize(size2);
        if (mode != 1073741824 && mode != Integer.MIN_VALUE) {
            this.mWidth = 0;
        }
        else {
            this.mWidth = size;
        }
        if (mode2 != Integer.MIN_VALUE && mode2 != 0) {
            this.mHeight = size2;
        }
        else {
            this.mHeight = this.dipToPx(18);
        }
        this.setMeasuredDimension(this.mWidth, this.mHeight);
    }
    
    public void setCurrentCount(final float n) {
        this.mCurrentCount = Math.min(n, this.mMaxCount);
        this.invalidate();
    }
    
    public void setMaxCount(final float mMaxCount) {
        this.mMaxCount = mMaxCount;
    }
}
